package org.example.supplychain.mapper;

import org.apache.ibatis.annotations.*;
import org.example.supplychain.domain.Supplier;

import java.util.List;

/**
 * 供应商管理的mapper
 */
@Mapper
public interface SupplierMapper {
    /**
     * 添加供应商
     * 传过来一个供应商，插入到数据库中，id索引自增
     *
     * @param supplier 供应商
     */
    @Insert("INSERT INTO supplier(supplier_name,mark,place,phone) VALUES (#{supplierName},#{mark},#{place},#{phone})")
    void addSupplier(Supplier supplier);

    /**
     * 删除供应商
     * 根据供应商名删除供应商
     *
     * @param supplierName 供应商名
     */
    @Delete("DELETE FROM supplier WHERE supplier_name = #{supplierName}")
    void deleteSupplierBySupplierName(String supplierName);

    /**
     * 更新供应商
     * 传过来一个供应商实例，更新数据库中的供应商信息
     *
     * @param supplier 供应商
     */
    @Update("UPDATE supplier SET mark = ${mark}, place=#{place},phone=#{phone} WHERE supplier_name = #{supplierName}")
    void updateSupplier(Supplier supplier);

    @Update("UPDATE supplier SET phone = #{phone} WHERE supplier_name = #{supplierName}")
    void updatePhone(Supplier supplier);

    @Update("UPDATE supplier SET mark = #{mark} WHERE supplier_name = #{supplierName}")
    void updateMark(Supplier supplier);

    @Update("UPDATE supplier SET place = #{place} WHERE supplier_name = #{supplierName}")
    void updatePlace(Supplier supplier);

    /**
     * 根据供应商名获取供应商
     *
     * @param supplierName 供应商名
     * @return 供应商实例
     */
    @Select("SELECT * FROM supplier WHERE supplier_name = #{supplierName}")
    Supplier getSupplierBySupplierName(String supplierName);

    /**
     * 获取所有供应商
     *
     * @return 所有供应商
     */
    @Select("SELECT * FROM supplier")
    List<Supplier> getAllSuppliers();
}
